<?php

namespace App\Api\Helpers\Push;


include_once __DIR__.'/../../Controllers/php/sdk/push.php';
class MiPush
{

    protected $title;
    protected $content;
    protected $value;
    protected $from;
    protected $to;


    public static function make(){
        return new MiPush();
    }

    /**
     * @param $value
     * @return $this
     */
    public function setValue($value)
    {
        $this->value = $value;
        return $this;
    }


    public function setTitle($title)
    {
        $this->title = $title;
        return $this;
    }


    public function setContent($content)
    {
        $this->content = $content;
        return $this;
    }


    public function setFrom($from)
    {
        $this->from = $from;
        return $this;
    }


    public function setTo($to)
    {
        $this->to = $to;
        return $this;
    }

    public function send(){

        $push = new \push();


        $push::$title=$this->title;
        $push::$desc=$this->content;
        $push::$value=$this->value;

        $aliasList = [];


        if (is_array($this->to)){

            foreach ($this->to as $to){
                $aliasList[] += $to->regId;
            }
        }else{

            $aliasList[] = $this->to->regId;
        }

        if (empty($aliasList)){
            dd('发送用户不能为为空');
        }

        $push::$aliasList=$aliasList;

        return $push->androidPush();
    }


    /*
    * 消息推送
    */
    public function push($title,$desc,$aliasList,$value){
        $push = new \push();
        $push::$title=$title;
        $push::$desc=$desc;
        $push::$value=$value;
        $push::$aliasList=$aliasList;
        return $push->androidPush();
    }


}